package cn.assumejson.springframework.service;

import cn.assumejson.springframework.bean.IUserDao;
import cn.assumejson.springframework.beans.context.ApplicationContext;
import cn.assumejson.springframework.beans.context.ApplicationContextAware;
import cn.assumejson.springframework.beans.factory.*;
import cn.assumejson.springframework.dao.UserDao;
import cn.hutool.core.lang.Console;

/**
 * @Author Mr. Li
 * @Date 2021/11/29 23:35
 * @Version 1.0
 */
public class UserService implements BeanNameAware, BeanClassLoaderAware, ApplicationContextAware, BeanFactoryAware {
    private String uId;
    private String company;
    private String location;
    private IUserDao userDao;

    public void queryUserInfo() {
        System.out.println("查询用户信息" + userDao.queryUserName(uId));
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getLocation() {
        return location;
    }

    @Override
    public String toString() {
        return "UserService{" +
                "uId='" + uId + '\'' +
                ", company='" + company + '\'' +
                ", location='" + location + '\'' +
                ", userDao=" + userDao +
                '}';
    }

    private ApplicationContext applicationContext;
    private ClassLoader classLoader;
    private BeanFactory beanFactory;
    private String name;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
        Console.log(">>>>>>>>>>>>>>>>>>>>>>>>>setApplicationContext is running : {}", applicationContext);
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        this.classLoader = classLoader;
        Console.log(">>>>>>>>>>>>>>>>>>>>>>>>>setBeanClassLoader is running : {}", classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
        Console.log(">>>>>>>>>>>>>>>>>>>>>>>>>setBeanFactory is running : {}", beanFactory);
    }

    @Override
    public void setBeanName(String name) {
        this.name = name;
        Console.log(">>>>>>>>>>>>>>>>>>>>>>>>>setBeanName is running : {}", name);
    }
}
// V0.7
// //public class UserService implements InitializingBean, DisposableBean {
//    private String uId;
//    private String company;
//    private String location;
//    private UserDao userDao;
//
//    public void queryUserInfo() {
//        System.out.println("查询用户信息" + userDao.queryUserName(uId));
//    }
//
//    public void setLocation(String location) {
//        this.location = location;
//    }
//
//    public String getLocation() {
//        return location;
//    }
//
//    @Override
//    public String toString() {
//        return "UserService{" +
//                "uId='" + uId + '\'' +
//                ", company='" + company + '\'' +
//                ", location='" + location + '\'' +
//                ", userDao=" + userDao +
//                '}';
//    }
//
//    @Override
//    public void destroy() throws Exception {
//        System.out.println("执行：UserService.destroy");
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        System.out.println("执行：UserService.afterPropertiesSet");
//    }
//}

//package cn.assumejson.springframework.service;
//
//import cn.assumejson.springframework.dao.UserDao;
//
///**
// * @Author Mr. Li
// * @Date 2021/11/29 23:35
// * @Version 1.0
// */
//public class UserService {
//    private String uId;
//    private String company;
//    private String location;
//    private UserDao userDao;
//
//    public void queryUserInfo() {
//        System.out.println("查询用户信息" + userDao.queryUserName(uId));
//    }
//
//    public void setLocation(String location) {
//        this.location = location;
//    }
//
//    public String getLocation() {
//        return location;
//    }
//
//    @Override
//    public String toString() {
//        return "UserService{" +
//                "uId='" + uId + '\'' +
//                ", company='" + company + '\'' +
//                ", location='" + location + '\'' +
//                ", userDao=" + userDao +
//                '}';
//    }
//}

